package com.example.controller;

import com.example.entity.CommonResult;
import com.example.service.StorageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author: 21050134
 * @date: 2023/10/20 16:22
 * @description:
 */
@RestController
@Slf4j
public class StorageController {
	@Resource
	private StorageService storageService;

	@Value("${server.port}")
	private String serverPort;

	@PostMapping(value = "/storage/decrease")
	public CommonResult decrease(@RequestParam("productId") Long productId,@RequestParam("count") Integer count){
		int decrease = storageService.decrease(productId,count);
		CommonResult result;
		if(decrease > 0){
			result = new CommonResult(200,"from mysql,serverPort: " + serverPort,decrease);
		}else{
			result = new CommonResult(505,"from mysql,serverPort: " + serverPort,"库存扣减失败");
		}
		return result;
	}



}
